<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta name="referrer" content="no-referrer"><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>14.Python面向对象 | 王扣笔记</title><meta name="author" content="王扣"><meta name="copyright" content="王扣"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="Python第二阶段 - 面向对象 章节目录 [!WARNING|label:本章需要学习的内容]   初识对象 成员方法 类和对象 构造方法 其他内置方法 封装 继承 类型注解 多态 综合案例  初识对象 教学视频       PPT资料        代码演示  1234567891011121314151617181920212223242526# 1. 设计一个类class Student">
<meta property="og:type" content="article">
<meta property="og:title" content="14.Python面向对象">
<meta property="og:url" content="http://grace.666443.xyz/posts/6ebaa02b.html">
<meta property="og:site_name" content="王扣笔记">
<meta property="og:description" content="Python第二阶段 - 面向对象 章节目录 [!WARNING|label:本章需要学习的内容]   初识对象 成员方法 类和对象 构造方法 其他内置方法 封装 继承 类型注解 多态 综合案例  初识对象 教学视频       PPT资料        代码演示  1234567891011121314151617181920212223242526# 1. 设计一个类class Student">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://p.ananas.chaoxing.com/star3/origin/d24d9bfcd4ce3f910d6b5cdc78676d75.png">
<meta property="article:published_time" content="2022-12-08T12:10:47.000Z">
<meta property="article:modified_time" content="2022-12-08T12:12:20.618Z">
<meta property="article:author" content="王扣">
<meta property="article:tag" content="笔记 开发">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://p.ananas.chaoxing.com/star3/origin/d24d9bfcd4ce3f910d6b5cdc78676d75.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="http://grace.666443.xyz/posts/6ebaa02b"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":true,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#1f1f1f","position":"bottom-left"},
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '14.Python面向对象',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-12-08 20:12:20'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 5.4.2"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">22</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">1</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">4</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-heartbeat"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/photos/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://p.ananas.chaoxing.com/star3/origin/d24d9bfcd4ce3f910d6b5cdc78676d75.png')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">王扣笔记</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-heartbeat"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/photos/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">14.Python面向对象</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2022-12-08T12:10:47.000Z" title="发表于 2022-12-08 20:10:47">2022-12-08</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-12-08T12:12:20.618Z" title="更新于 2022-12-08 20:12:20">2022-12-08</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/python%E5%9F%BA%E7%A1%80/">python基础</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="14.Python面向对象"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="Python第二阶段-面向对象"><a href="#Python第二阶段-面向对象" class="headerlink" title="Python第二阶段 - 面向对象"></a>Python第二阶段 - 面向对象</h1><hr>
<h2 id="章节目录"><a href="#章节目录" class="headerlink" title="章节目录"></a><strong>章节目录</strong></h2><blockquote>
<p>[!WARNING|label:本章需要学习的内容]</p>
</blockquote>
<ul>
<li>初识对象</li>
<li>成员方法</li>
<li>类和对象</li>
<li>构造方法</li>
<li>其他内置方法</li>
<li>封装</li>
<li>继承</li>
<li>类型注解</li>
<li>多态</li>
<li>综合案例</li>
</ul>
<h2 id="初识对象"><a href="#初识对象" class="headerlink" title="初识对象"></a><strong>初识对象</strong></h2><blockquote>
<p>教学视频</p>
</blockquote>
 <iframe src="//player.bilibili.com/player.html?aid=941747210&bvid=BV1qW4y1a7fU&cid=821715115&page=111" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" height="500"> </iframe>

<blockquote>
<p>PPT资料</p>
</blockquote>
<p> <img src="https://p.ananas.chaoxing.com/star3/origin/87f2c249750e6e1dc172a671da23627e.png" alt="1"><br> <img src="https://p.ananas.chaoxing.com/star3/origin/e171764279c52f5348381faad2cd841a.png" alt="2"><br> <img src="https://p.ananas.chaoxing.com/star3/origin/ce10e6e21e3fc54aa1098d04a63ff1ee.png" alt="3"><br> <img src="https://p.ananas.chaoxing.com/star3/origin/4e12ce3d86c53de25657160d025c8ce5.png" alt="4"></p>
<blockquote>
<p>代码演示</p>
</blockquote>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 1. 设计一个类</span></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Student</span>:</span><br><span class="line">    name = <span class="literal">None</span>  <span class="comment"># 学生姓名</span></span><br><span class="line">    gender = <span class="literal">None</span>  <span class="comment"># 性别</span></span><br><span class="line">    nationality = <span class="literal">None</span>  <span class="comment"># 国籍</span></span><br><span class="line">    native_place = <span class="literal">None</span>  <span class="comment"># 籍贯</span></span><br><span class="line">    age = <span class="literal">None</span>  <span class="comment"># 年龄</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 2.创建一个对象</span></span><br><span class="line">stu_1 = Student()</span><br><span class="line"></span><br><span class="line"><span class="comment"># 3.对象属性赋值</span></span><br><span class="line">stu_1.name = <span class="string">&quot;林俊杰&quot;</span></span><br><span class="line">stu_1.gender = <span class="string">&quot;男&quot;</span></span><br><span class="line">stu_1.nationality = <span class="string">&quot;中国&quot;</span></span><br><span class="line">stu_1.native_place = <span class="string">&quot;山东&quot;</span></span><br><span class="line">stu_1.age = <span class="number">18</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 4.获取对象中记录的信息</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">print</span>(stu_1.name)</span><br><span class="line"><span class="built_in">print</span>(stu_1.gender)</span><br><span class="line"><span class="built_in">print</span>(stu_1.nationality)</span><br><span class="line"><span class="built_in">print</span>(stu_1.native_place)</span><br><span class="line"><span class="built_in">print</span>(stu_1.age)</span><br></pre></td></tr></table></figure>

<h2 id="成员方法"><a href="#成员方法" class="headerlink" title="成员方法"></a><strong>成员方法</strong></h2><blockquote>
<p>教学视频</p>
</blockquote>
<iframe src="//player.bilibili.com/player.html?aid=941747210&bvid=BV1qW4y1a7fU&cid=821597031&page=112" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" height="500"> </iframe>

<blockquote>
<p>PPT资料</p>
</blockquote>
<p> <img src="https://p.ananas.chaoxing.com/star3/origin/e0500ad87d7c7ee1bcc9e2a5f9e255ed.png" alt="1"><br> <img src="https://p.ananas.chaoxing.com/star3/origin/c44e8a9bcebbd9fb8b0310ac95ea53e3.png" alt="2"><br> <img src="https://p.ananas.chaoxing.com/star3/origin/5a9bfb846429ce7eadc0929b9934dcff.png" alt="3"><br> <img src="https://p.ananas.chaoxing.com/star3/origin/8c4c15ff09e994ebe218459470d9e72b.png" alt="4"><br> <img src="https://p.ananas.chaoxing.com/star3/origin/950dd1a55caa31886ef1b568297fa28a.png" alt="5"><br> <img src="https://p.ananas.chaoxing.com/star3/origin/f771ba911036ca6d32112899b7dd337b.png" alt="6"><br> <img src="https://p.ananas.chaoxing.com/star3/origin/0e90d639293d101cb31d86aab11fd9f9.png" alt="7"></p>
<blockquote>
<p>代码演示</p>
</blockquote>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 定义一个带有成员方法的类</span></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Student</span>:</span><br><span class="line">    name = <span class="literal">None</span>  <span class="comment"># 学生姓名</span></span><br><span class="line"></span><br><span class="line">    <span class="comment"># self必须要写，参数self 可以当做不存在 不占用参数位置</span></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">say_hi</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">f&quot;大家好，我是<span class="subst">&#123;self.name&#125;</span>,欢迎大家多多关照!&quot;</span>)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">say_hi2</span>(<span class="params">self, msg</span>):</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">f&quot;大家好，我是<span class="subst">&#123;self.name&#125;</span>,<span class="subst">&#123;msg&#125;</span>&quot;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 下面是调用</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 1.实例化一个类对象</span></span><br><span class="line">student = Student()</span><br><span class="line"></span><br><span class="line"><span class="comment"># 2.使用成员变量和方法</span></span><br><span class="line">student.name = <span class="string">&#x27;张三&#x27;</span></span><br><span class="line"></span><br><span class="line">student.say_hi()</span><br><span class="line">student.say_hi2(<span class="string">&quot;测试参数msg&quot;</span>) </span><br></pre></td></tr></table></figure>


<h2 id="类和对象"><a href="#类和对象" class="headerlink" title="类和对象"></a><strong>类和对象</strong></h2><blockquote>
<p>视频教学</p>
</blockquote>
<iframe src="//player.bilibili.com/player.html?aid=941747210&bvid=BV1qW4y1a7fU&cid=821598362&page=113" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" height="500"> </iframe>

<blockquote>
<p>PPT资料</p>
</blockquote>
<p><img src="https://p.ananas.chaoxing.com/star3/origin/88bdaf9bbd5d39d64de36db3fa12c5e1.png" alt="1"><br><img src="https://p.ananas.chaoxing.com/star3/origin/03a8fcdb677ef7a79a56fc8a17e9c979.png" alt="2"><br><img src="https://p.ananas.chaoxing.com/star3/origin/27598f1a07394863788aa82f817eedb9.png" alt="3"><br><img src="https://p.ananas.chaoxing.com/star3/origin/a4f0f1225321a58c921fcdc3622e76c1.png" alt="4"><br><img src="https://p.ananas.chaoxing.com/star3/origin/06a3cf4d49e5605e585c62eb43c27947.png" alt="5"><br><img src="https://p.ananas.chaoxing.com/star3/origin/e3791d8a166b901559a86a7e44b1957c.png" alt="6"><br><img src="https://p.ananas.chaoxing.com/star3/origin/0d5b2dd4d1423e6e1ed9e7625fd28fa7.png" alt="7"><br><img src="https://p.ananas.chaoxing.com/star3/origin/cca2c7a758309a324cfaac3f6a892299.png" alt="8"><br><img src="https://p.ananas.chaoxing.com/star3/origin/95bb76320ad0f338ac2b3cf2d703a69e.png" alt="9"></p>
<blockquote>
<p>代码演示</p>
</blockquote>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 设计一个闹钟类</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Clock</span>:</span><br><span class="line">    <span class="built_in">id</span> = <span class="literal">None</span>  <span class="comment"># 序列化</span></span><br><span class="line">    price = <span class="literal">None</span>  <span class="comment"># 价格</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">ring</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="comment"># 这个是Windows系统的，Mac会有报错</span></span><br><span class="line">        <span class="keyword">import</span> winsound</span><br><span class="line">        winsound.Beep(<span class="number">2000</span>, <span class="number">3000</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 构建2个闹钟对象并工作</span></span><br><span class="line"></span><br><span class="line">c1 = Clock()</span><br><span class="line">c1.<span class="built_in">id</span> = <span class="string">&#x27;0001&#x27;</span></span><br><span class="line">c1.price = <span class="number">19.65</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">print</span>(<span class="string">f&quot;闹钟id: <span class="subst">&#123;c1.<span class="built_in">id</span>&#125;</span> ,价格 : <span class="subst">&#123;c1.price&#125;</span>&quot;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 响</span></span><br><span class="line">c1.ring() </span><br></pre></td></tr></table></figure>

<h2 id="构造方法"><a href="#构造方法" class="headerlink" title="构造方法"></a><strong>构造方法</strong></h2><blockquote>
<p>教学视频</p>
</blockquote>
<iframe src="//player.bilibili.com/player.html?aid=941747210&bvid=BV1qW4y1a7fU&cid=821605517&page=114" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" height='500'> </iframe>

<blockquote>
<p>PPT资料</p>
</blockquote>
<p><img src="https://p.ananas.chaoxing.com/star3/origin/f2152620cd118795c59f8a7c10d78b7d.png" alt="1"><br><img src="https://p.ananas.chaoxing.com/star3/origin/bdd20ceb77bcf8d4ee42fd3d57ed68a5.png" alt="2"><br><img src="https://p.ananas.chaoxing.com/star3/origin/e23d0a2bc1ffc18116be0415141e93c9.png" alt="3"><br><img src="https://p.ananas.chaoxing.com/star3/origin/cde9ca2bef9c9ce12ea4b2b485d806bc.png" alt="4"><br><img src="https://p.ananas.chaoxing.com/star3/origin/4328eafb28567ab71936716ef12defc9.png" alt="5"></p>
<blockquote>
<p>代码演示</p>
</blockquote>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 构造方法</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 演示使用构造方法对成员变量进行赋值</span></span><br><span class="line"><span class="comment"># 构造方法的名称： __init__</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Students</span>:</span><br><span class="line">    name = <span class="literal">None</span></span><br><span class="line">    age = <span class="literal">None</span></span><br><span class="line">    tel = <span class="literal">None</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__init__</span>(<span class="params">self, name, age, tel</span>):</span><br><span class="line">        self.name = name</span><br><span class="line">        self.age = age</span><br><span class="line">        self.tel = tel</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">f&quot;Stu类创建了一个对象，我是<span class="subst">&#123;self.name&#125;</span>,今年<span class="subst">&#123;self.age&#125;</span>岁，我的手机号码为<span class="subst">&#123;self.tel&#125;</span>&quot;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># ctrl + p 提示参数</span></span><br><span class="line">s1 = Students(<span class="string">&quot;张三&quot;</span>, <span class="number">18</span>, <span class="string">&#x27;18888884444&#x27;</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="其他内置方法"><a href="#其他内置方法" class="headerlink" title="其他内置方法"></a><strong>其他内置方法</strong></h2><blockquote>
<p>教学视频</p>
</blockquote>
<iframe src="//player.bilibili.com/player.html?aid=941747210&bvid=BV1qW4y1a7fU&cid=821596021&page=115" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" height='500'> </iframe>

<blockquote>
<p>PPT资料</p>
</blockquote>
<p><img src="https://p.ananas.chaoxing.com/star3/origin/7e0006359991708195bd08c8322c87b2.png" alt="1"><br><img src="https://p.ananas.chaoxing.com/star3/origin/42bb2fcfd6f64477f99b9164f71212b2.png" alt="2"><br><img src="https://p.ananas.chaoxing.com/star3/origin/00bea1713f7666ee1a083273ce17ea98.png" alt="3"><br><img src="https://p.ananas.chaoxing.com/star3/origin/6290bd105d74f4f79e39ae6699cc8a4c.png" alt="4"><br><img src="https://p.ananas.chaoxing.com/star3/origin/23389ef8f13ab78d9de327747f1a8482.png" alt="5"><br><img src="https://p.ananas.chaoxing.com/star3/origin/089e140c4e9a99c363dadf6ae7e79329.png" alt="6"><br><img src="https://p.ananas.chaoxing.com/star3/origin/9da099f8c6c26bc6883d82c823acff30.png" alt="7"></p>
<blockquote>
<p>代码演示</p>
</blockquote>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">其他内置方法，学习常用的几个</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Student</span>:</span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__init__</span>(<span class="params">self, name, age</span>):</span><br><span class="line">        self.name = name  <span class="comment"># 定义学生姓名属性，并赋值</span></span><br><span class="line">        self.age = age  <span class="comment"># 定义学生年龄属性，并赋值</span></span><br><span class="line"></span><br><span class="line">    <span class="comment"># __str__ 魔术方法 字符串方法</span></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__str__</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="keyword">return</span> <span class="string">f&quot;Student类对象，name:<span class="subst">&#123;self.name&#125;</span> , age:<span class="subst">&#123;self.age&#125;</span>&quot;</span></span><br><span class="line"></span><br><span class="line">    <span class="comment"># __lt__ 魔术方法 小于。大于符号比较</span></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__lt__</span>(<span class="params">self, other</span>):</span><br><span class="line">        <span class="keyword">return</span> self.age &lt; other.age</span><br><span class="line"></span><br><span class="line">    <span class="comment"># __le__ 魔术方法 小于等于、大于等于符号比较</span></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__le__</span>(<span class="params">self, other</span>):</span><br><span class="line">        <span class="keyword">return</span> self.age &lt;= other.age</span><br><span class="line"></span><br><span class="line">    <span class="comment"># __eq__ 魔术方法 == 符号比较</span></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__eq__</span>(<span class="params">self, other</span>):</span><br><span class="line">        <span class="keyword">return</span> self.age == other.age</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">stu1 = Student(<span class="string">&quot;周杰伦&quot;</span>, <span class="number">31</span>)</span><br><span class="line">stu2 = Student(<span class="string">&quot;林俊杰&quot;</span>, <span class="number">36</span>)</span><br><span class="line"></span><br><span class="line"><span class="built_in">print</span>(stu1)</span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">str</span>(stu1))</span><br><span class="line"></span><br><span class="line"><span class="built_in">print</span>(stu1 &lt; stu2)</span><br><span class="line"><span class="built_in">print</span>(stu1 &gt; stu2)</span><br><span class="line"></span><br><span class="line"><span class="built_in">print</span>(stu1 &lt;= stu2)</span><br><span class="line"><span class="built_in">print</span>(stu1 &gt;= stu2)</span><br><span class="line"></span><br><span class="line"><span class="built_in">print</span>(stu1 == stu2)</span><br></pre></td></tr></table></figure>

<h2 id="封装"><a href="#封装" class="headerlink" title="封装"></a><strong>封装</strong></h2><blockquote>
<p>教学视频</p>
</blockquote>
<iframe src="//player.bilibili.com/player.html?aid=941747210&bvid=BV1qW4y1a7fU&cid=821600956&page=116" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" height='500'> </iframe>

<blockquote>
<p>PPT资料</p>
</blockquote>
<p><img src="https://p.ananas.chaoxing.com/star3/origin/241dd1002b9b0698bdd243e48f578bb7.png" alt="1"><br><img src="https://p.ananas.chaoxing.com/star3/origin/b3a04ae5afc1b10abb98606a6d560c56.png" alt="2"><br><img src="https://p.ananas.chaoxing.com/star3/origin/1407e2a339896ab56699379080cda843.png" alt="3"><br><img src="https://p.ananas.chaoxing.com/star3/origin/620a401abe0543f08a8a8d0d13355c19.png" alt="4"><br><img src="https://p.ananas.chaoxing.com/star3/origin/072d548672e96a027b1666ad4f398a93.png" alt="5"><br><img src="https://p.ananas.chaoxing.com/star3/origin/9b498c868b4165b0eec309bf8b945d1a.png" alt="6"><br><img src="https://p.ananas.chaoxing.com/star3/origin/1f20a719f0e2ee42e5cf027c7f04d931.png" alt="7"></p>
<blockquote>
<p>代码演示</p>
</blockquote>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">    演示面向对象封装思想中私有成员的使用</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 定义一个类，内含私有成员变量和私有成员方法</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Phone</span>:</span><br><span class="line">    __current_voltage = <span class="number">0</span>  <span class="comment"># 当前手机运行电压 私有成员变量</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__keep_single_core</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">        私有成员方法</span></span><br><span class="line"><span class="string">        :return:</span></span><br><span class="line"><span class="string">        &quot;&quot;&quot;</span></span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&quot;让CPU以单核模式运行&quot;</span>)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">call_by_5g</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="keyword">if</span> self.__current_voltage &gt;= <span class="number">1</span>:</span><br><span class="line">            <span class="built_in">print</span>(<span class="string">&quot;5g通话已开启&quot;</span>)</span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            <span class="comment"># 电量&lt;1 运行单核模式</span></span><br><span class="line">            self.__keep_single_core()</span><br><span class="line">            <span class="built_in">print</span>(<span class="string">&quot;电量不足，无法使用5g通话，并已设置为单核运行进行省电。&quot;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">phone = Phone()</span><br><span class="line"></span><br><span class="line"><span class="comment"># 私有成员方法无法直接调用，此处报错</span></span><br><span class="line"><span class="comment"># phone.__keep_single_core()</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 私有成员变量 也无法直接使用，此处报错</span></span><br><span class="line"><span class="comment"># print(phone.__current_voltage)</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">phone.call_by_5g()</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><img src="https://p.ananas.chaoxing.com/star3/origin/88d2bf709e9b720034bf3ed72d13698e.png" alt="8"></p>
<h2 id="封装-练习题讲解"><a href="#封装-练习题讲解" class="headerlink" title="封装 - 练习题讲解"></a><strong>封装 - 练习题讲解</strong></h2><blockquote>
<p>视频讲解</p>
</blockquote>
<iframe src="//player.bilibili.com/player.html?aid=941747210&bvid=BV1qW4y1a7fU&cid=821598016&page=117" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" height='500'> </iframe>

<blockquote>
<p>练习题，方便更好的理解封装</p>
</blockquote>
<p><img src="https://p.ananas.chaoxing.com/star3/origin/dff99b97b6a9b0a53944c78a66f70db3.png" alt="9"></p>
<blockquote>
<p>练习题代码演示</p>
</blockquote>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">练习题：设计带有私有成员的手机</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Phone</span>:</span><br><span class="line">    <span class="comment"># 提供私有成员变量： __is_5g_enable</span></span><br><span class="line">    __is_5g_enable = <span class="literal">False</span>  <span class="comment"># 5g状态</span></span><br><span class="line"></span><br><span class="line">    <span class="comment"># 提供私有成员方法 ：__check_5g()</span></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__check_5g</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="keyword">if</span> self.__is_5g_enable:</span><br><span class="line">            <span class="built_in">print</span>(<span class="string">&quot;5g开启&quot;</span>)</span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            <span class="built_in">print</span>(<span class="string">&quot;5g关闭，使用4g网络&quot;</span>)</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 提供公开成员方法：call_by_5g()</span></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">call_by_5g</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="comment"># 判断5g网络状态</span></span><br><span class="line">        self.__check_5g()</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&quot;正在通话中.....&quot;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 调用</span></span><br><span class="line">phone = Phone()</span><br><span class="line">phone.call_by_5g()</span><br></pre></td></tr></table></figure>

<h2 id="继承"><a href="#继承" class="headerlink" title="继承"></a><strong>继承</strong></h2><h3 id="1-继承的基础语法"><a href="#1-继承的基础语法" class="headerlink" title="1.继承的基础语法"></a>1.继承的基础语法</h3><blockquote>
<p>教学视频</p>
</blockquote>
<iframe src="//player.bilibili.com/player.html?aid=941747210&bvid=BV1qW4y1a7fU&cid=821612725&page=118" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" height='500'> </iframe>

<blockquote>
<p>PPT资料</p>
</blockquote>
<p><img src="https://p.ananas.chaoxing.com/star3/origin/4bdbdbdd0dc36e8e48ba650ba191b8db.png" alt="1"><br><img src="https://p.ananas.chaoxing.com/star3/origin/e8dc0e3b59db332d60450e6701fad80e.png" alt="2"><br><img src="https://p.ananas.chaoxing.com/star3/origin/06b06d812e2705c081734f84801df078.png" alt="3"><br><img src="https://p.ananas.chaoxing.com/star3/origin/cfec992fc2934d9bd8275720291247d7.png" alt="4"><br><img src="https://p.ananas.chaoxing.com/star3/origin/2e8bec19eb14ab552c1546d860380eb8.png" alt="5"></p>
<blockquote>
<p>代码演示</p>
</blockquote>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">演示单继承</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Phone</span>:</span><br><span class="line">    IMEI = <span class="literal">None</span>  <span class="comment"># 序列号</span></span><br><span class="line">    producer = <span class="string">&#x27;HM&#x27;</span>  <span class="comment"># 厂商</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">call_by_4g</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&quot;4g通话&quot;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 单继承</span></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Phone2022</span>(<span class="title class_ inherited__">Phone</span>):</span><br><span class="line">    face_id = <span class="string">&quot;10001&quot;</span>  <span class="comment"># 面部识别ID</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">call_by_5g</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&quot;5g通话&quot;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 调用继承的类</span></span><br><span class="line">phone_1 = Phone2022()</span><br><span class="line">phone_1.call_by_5g()</span><br></pre></td></tr></table></figure>

<p><img src="https://p.ananas.chaoxing.com/star3/origin/fa954b86a9d78be93654030df4cd7703.png" alt="6"></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> <span class="title class_">Phone_base</span>:</span><br><span class="line">    IMEI = <span class="literal">None</span>  <span class="comment"># 序列号</span></span><br><span class="line">    producer = <span class="string">&#x27;HM&#x27;</span>  <span class="comment"># 厂商</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">call_by_4g</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&quot;4g通话&quot;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">NFCReader</span>:</span><br><span class="line">    nfc_type = <span class="string">&quot;第五代NFC&quot;</span></span><br><span class="line">    producer = <span class="string">&#x27;HM厂商&#x27;</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">read_card</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&quot;NFC读卡操作&quot;</span>)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">write_card</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&quot;NFC写卡操作&quot;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">RemoteControl</span>:</span><br><span class="line">    rc_type = <span class="string">&quot;红外遥控&quot;</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">control</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&quot;红外遥控开启了&quot;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">myPhone_1</span>(Phone_base, RemoteControl, NFCReader):</span><br><span class="line">    <span class="comment"># 多继承，没有啥再补充的了</span></span><br><span class="line">    <span class="comment"># 使用pass关键字占位语句</span></span><br><span class="line">    <span class="comment"># 来保证函数，方法，类的定义完整性，表示无内容 空的意思</span></span><br><span class="line">    <span class="keyword">pass</span></span><br></pre></td></tr></table></figure>

<p><img src="https://p.ananas.chaoxing.com/star3/origin/57a3b486c85a9ff6b4ed866745a48cb6.png" alt="7"></p>
<h3 id="2-复写和使用父类成员"><a href="#2-复写和使用父类成员" class="headerlink" title="2.复写和使用父类成员"></a>2.复写和使用父类成员</h3><blockquote>
<p>教学视频</p>
</blockquote>
<iframe src="//player.bilibili.com/player.html?aid=941747210&bvid=BV1qW4y1a7fU&cid=821599315&page=119" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" height='500'> </iframe>

<blockquote>
<p>PPT资料</p>
</blockquote>
<p><img src="https://p.ananas.chaoxing.com/star3/origin/2f27e656a35bbe1352d5c34a9050b6a7.png" alt="1"><br><img src="https://p.ananas.chaoxing.com/star3/origin/5687886bc42cc63ffcc79bee0ec353cc.png" alt="2"></p>
<blockquote>
<p>代码演示</p>
</blockquote>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 复写</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 定义父类</span></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Phone</span>:</span><br><span class="line">    IMEI = <span class="literal">None</span>  <span class="comment"># 序列号</span></span><br><span class="line">    producer = <span class="string">&quot;HM&quot;</span>  <span class="comment"># 厂商</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">call_by_5g</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&quot;我是父类，5g通话&quot;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 定义子类，复写父类成员</span></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">MyPhone</span>(<span class="title class_ inherited__">Phone</span>):</span><br><span class="line">    producer = <span class="string">&quot;IThEIMA&quot;</span>  <span class="comment"># 复写父类成员属性</span></span><br><span class="line"></span><br><span class="line">    <span class="comment"># 复写父类成员方法</span></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">call_by_5g</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&quot;开启CPU单核模式，确保通话的时候省电&quot;</span>)</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&quot;使用5g网络进行通话&quot;</span>)</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&quot;关闭CPU单核模式，确保性能&quot;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">myPhone1 = MyPhone()</span><br><span class="line"><span class="built_in">print</span>(myPhone1.producer)</span><br><span class="line">myPhone1.call_by_5g()</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><img src="https://p.ananas.chaoxing.com/star3/origin/1d693a6bbace1ea7627929b7d70709b7.png" alt="3"><br><img src="https://p.ananas.chaoxing.com/star3/origin/de6f6921926c316170773836767233f5.png" alt="4"><br><img src="https://p.ananas.chaoxing.com/star3/origin/a74b8ee65619f421ceb8c812b512cf88.png" alt="5"></p>
<h2 id="类型注解"><a href="#类型注解" class="headerlink" title="类型注解"></a><strong>类型注解</strong></h2><h3 id="1-变量的类型注解"><a href="#1-变量的类型注解" class="headerlink" title="1.变量的类型注解"></a>1.变量的类型注解</h3><blockquote>
<p>变量的类型注解 教学视频</p>
</blockquote>
<iframe src="//player.bilibili.com/player.html?aid=941747210&bvid=BV1qW4y1a7fU&cid=821606648&page=120" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"> </iframe>

<blockquote>
<p>PPT资料</p>
</blockquote>
<p><img src="https://p.ananas.chaoxing.com/star3/origin/46b88e3b96713d1e65aabf2ad333e796.png" alt="1"><br><img src="https://p.ananas.chaoxing.com/star3/origin/b501911259e20f476364e84e1087714d.png" alt="2"><br><img src="https://p.ananas.chaoxing.com/star3/origin/1a0ca251b18882b041455e749d51c399.png" alt="3"><br><img src="https://p.ananas.chaoxing.com/star3/origin/7daf324090aba9c72bc24bbd4ead5662.png" alt="4"><br><img src="https://p.ananas.chaoxing.com/star3/origin/dc5cf84af37f3976225ad2a47c534460.png" alt="5"><br><img src="https://p.ananas.chaoxing.com/star3/origin/ec61fc264789f435d116f99aaf5741c0.png" alt="6"><br><img src="https://p.ananas.chaoxing.com/star3/origin/1d71fcb789c98f6540bc6c77f4f1a3d2.png" alt="7"><br><img src="https://p.ananas.chaoxing.com/star3/origin/cccb1521bb6fa4503fc6b22a68462cd3.png" alt="8"><br><img src="https://p.ananas.chaoxing.com/star3/origin/5bcc5b5e28550e06b82ce9fabd7de115.png" alt="9"><br><img src="https://p.ananas.chaoxing.com/star3/origin/de941b6a42653fbe5b97d7d9508d2bb8.png" alt="10"><br><img src="https://p.ananas.chaoxing.com/star3/origin/4b8ae66c9c8b8f280deac355f6693e61.png" alt="11"></p>
<h3 id="2-函数-方法-的类型注解"><a href="#2-函数-方法-的类型注解" class="headerlink" title="2.函数(方法)的类型注解"></a>2.函数(方法)的类型注解</h3><blockquote>
<p>教学视频</p>
</blockquote>
<iframe src="//player.bilibili.com/player.html?aid=941747210&bvid=BV1qW4y1a7fU&cid=821606127&page=121" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"> </iframe>

<blockquote>
<p>PPT资料</p>
</blockquote>
<p><img src="https://p.ananas.chaoxing.com/star3/origin/554c4d2559bfd6d41978c9bbb911b2cc.png" alt="1"><br><img src="https://p.ananas.chaoxing.com/star3/origin/6be0fce27e88f025394cc6cf33664aeb.png" alt="2"><br><img src="https://p.ananas.chaoxing.com/star3/origin/626ab07fe0680c6dd18c407763afef06.png" alt="3"><br><img src="https://p.ananas.chaoxing.com/star3/origin/04a34de296be216563892bd350b7932a.png" alt="4"></p>
<h3 id="3-Union类型"><a href="#3-Union类型" class="headerlink" title="3.Union类型"></a>3.Union类型</h3><blockquote>
<p>教学视频</p>
</blockquote>
<iframe src="//player.bilibili.com/player.html?aid=941747210&bvid=BV1qW4y1a7fU&cid=821607870&page=122" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"> </iframe>

<blockquote>
<p>PPT资料</p>
</blockquote>
<p><img src="https://p.ananas.chaoxing.com/star3/origin/2c8097d352d227fec8287d9e6cba0a5e.png" alt="1"><br><img src="https://p.ananas.chaoxing.com/star3/origin/dfa4660d4805b96014b0839f9f6dce07.png" alt="2"><br><img src="https://p.ananas.chaoxing.com/star3/origin/6eeccfdbb1d502e011800f32dc5e5553.png" alt="3"><br><img src="https://p.ananas.chaoxing.com/star3/origin/c6104b8ffe7bb634f107ee9947d98b71.png" alt="4"></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">演示 union联合类型注解</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 使用union类型，必须先导包</span></span><br><span class="line"><span class="keyword">from</span> typing <span class="keyword">import</span> <span class="type">Union</span></span><br><span class="line"></span><br><span class="line">my_list: <span class="built_in">list</span>[<span class="type">Union</span>[<span class="built_in">int</span>, <span class="built_in">str</span>]] = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">22</span>, <span class="string">&quot;黑马&quot;</span>]</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">func</span>(<span class="params">data: <span class="type">Union</span>[<span class="built_in">int</span>, <span class="built_in">str</span>]</span>) -&gt; <span class="type">Union</span>[<span class="built_in">int</span>, <span class="built_in">str</span>]:</span><br><span class="line">    <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">func(<span class="number">11</span>)</span><br></pre></td></tr></table></figure>


<h2 id="多态"><a href="#多态" class="headerlink" title="多态"></a><strong>多态</strong></h2><blockquote>
<p>教学视频</p>
</blockquote>
<iframe src="//player.bilibili.com/player.html?aid=941747210&bvid=BV1qW4y1a7fU&cid=821612403&page=123" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"> </iframe>

<blockquote>
<p>PPT资料</p>
</blockquote>
<p><img src="https://p.ananas.chaoxing.com/star3/origin/aa056d989be19f67e2a0f23b4bb589b5.png" alt="1"><br><img src="https://p.ananas.chaoxing.com/star3/origin/3451108a0fe0ca86647738f3af366a91.png" alt="2"><br><img src="https://p.ananas.chaoxing.com/star3/origin/4426e7b27d221f08a6b64fc085419c7c.png" alt="3"><br><img src="https://p.ananas.chaoxing.com/star3/origin/8161c569e42b8b0c1765bb7331c12ede.png" alt="4"><br><img src="https://p.ananas.chaoxing.com/star3/origin/2002a217fce73d146836764abdaad0ff.png" alt="5"><br><img src="https://p.ananas.chaoxing.com/star3/origin/316ac9a1782c81c22eb491d2159da179.png" alt="6"><br><img src="https://p.ananas.chaoxing.com/star3/origin/4cb38e9fa8f72038e49142c224818973.png" alt="7"></p>
<blockquote>
<p>代码演示</p>
</blockquote>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">演示面向对象的多态特性以及抽象类(接口)的使用</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 父类 （也是抽象类，抽象类：含有抽象方法的类称之为抽象类）</span></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Animal</span>:</span><br><span class="line">    <span class="comment"># 抽象方法；方法体是空实现的(pass)称之为抽象方法</span></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">speak</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 继承的子类</span></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Dog</span>(<span class="title class_ inherited__">Animal</span>):</span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">speak</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&quot;小狗叫，汪汪汪&quot;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 继承的子类</span></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Cat</span>(<span class="title class_ inherited__">Animal</span>):</span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">speak</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&quot;小猫叫，喵喵喵&quot;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">make_noise</span>(<span class="params">animal: Animal</span>):</span><br><span class="line">    <span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">    功能：制造噪音</span></span><br><span class="line"><span class="string">    :param animal:传递Animal的对象 或者继承Animal的子类</span></span><br><span class="line"><span class="string">    :return:</span></span><br><span class="line"><span class="string">    &quot;&quot;&quot;</span></span><br><span class="line">    animal.speak()</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 演示多态</span></span><br><span class="line">dog = Dog()</span><br><span class="line">cat = Cat()</span><br><span class="line"></span><br><span class="line">make_noise(dog)</span><br><span class="line">make_noise(cat)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># ===========================抽象类配合多态使用====================================</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 演示抽象类(案例以空调为例) 顶层设计</span></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">AC</span>:</span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">cool_wind</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="string">&quot;&quot;&quot;制冷&quot;&quot;&quot;</span></span><br><span class="line">        <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">hot_wind</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="string">&quot;&quot;&quot;制热&quot;&quot;&quot;</span></span><br><span class="line">        <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">swing_l_r</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="string">&quot;&quot;&quot;左右摆风&quot;&quot;&quot;</span></span><br><span class="line">        <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">#  底层实现</span></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Media_Ac</span>(<span class="title class_ inherited__">AC</span>):</span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">cool_wind</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&quot;美的空调制冷&quot;</span>)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">hot_wind</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&quot;美的空调制热&quot;</span>)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">swing_l_r</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&quot;美的的左右摆风&quot;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 底层实现</span></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Gree_Ac</span>(<span class="title class_ inherited__">AC</span>):</span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">cool_wind</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&quot;格力空调制冷&quot;</span>)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">hot_wind</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&quot;格力空调制热&quot;</span>)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">swing_l_r</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&quot;格力的左右摆风&quot;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 多态</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">make_cool</span>(<span class="params">AC</span>):</span><br><span class="line">    AC.cool_wind()</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">media_ac = Media_Ac()</span><br><span class="line">gree_ac = Gree_Ac()</span><br><span class="line"></span><br><span class="line">make_cool(media_ac)</span><br><span class="line">make_cool(gree_ac)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="数据分析的综合案例"><a href="#数据分析的综合案例" class="headerlink" title="数据分析的综合案例"></a><strong>数据分析的综合案例</strong></h2><p><strong>使用面向对象思想开发</strong></p>
<blockquote>
<p>教学视频</p>
</blockquote>
<iframe src="//player.bilibili.com/player.html?aid=941747210&bvid=BV1qW4y1a7fU&cid=821607901&page=124" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"> </iframe>

<h3 id="0-数据来源"><a href="#0-数据来源" class="headerlink" title="0.数据来源"></a>0.数据来源</h3><blockquote>
<p>数据高速网盘下载</p>
</blockquote>
<p><a target="_blank" rel="noopener" href="https://sharewh1.xuexi365.com/share/download/f026065ae13981301763048980016929">2011年1月销售数据.txt</a></p>
<p><a target="_blank" rel="noopener" href="https://sharewh1.xuexi365.com/share/download/bad161d366413e196c1a666854428bd7">2011年2月销售数据JSON.txt</a></p>
<h3 id="1-思路分析"><a href="#1-思路分析" class="headerlink" title="1.思路分析"></a>1.思路分析</h3><blockquote>
<p>PPT资料</p>
</blockquote>
<p><img src="https://p.ananas.chaoxing.com/star3/origin/a41133c13d5f8ab40b5e27b89818eeee.png" alt="1"><br><img src="https://p.ananas.chaoxing.com/star3/origin/0c116678a8ec2a61d7190646bb92182a.png" alt="2"><br><img src="https://p.ananas.chaoxing.com/star3/origin/71eecd353ef3184b22b2fa2d038749ae.png" alt="3"><br><img src="https://p.ananas.chaoxing.com/star3/origin/c0dbd05d1d4f32587a75237f0e42cb16.png" alt="4"></p>
<h3 id="2-代码目录-分为几个文件写的"><a href="#2-代码目录-分为几个文件写的" class="headerlink" title="2.代码目录 分为几个文件写的"></a>2.代码目录 分为几个文件写的</h3><p><img src="https://p.ananas.chaoxing.com/star3/origin/1bc1095573ea6592fe5f88a03e447a18.png" alt="5"></p>
<h3 id="3-代码文件-data-define-py"><a href="#3-代码文件-data-define-py" class="headerlink" title="3.代码文件 data_define.py"></a>3.代码文件 data_define.py</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">数据定义的类</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 记录数据的基础信息</span></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Record</span>:</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 多行数据同时点选快捷键，ALT + 鼠标选中</span></span><br><span class="line">    <span class="comment"># 通过构造函数赋初始值</span></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__init__</span>(<span class="params">self,date,order_id,money,province</span>):</span><br><span class="line">        self.date = date            <span class="comment"># 订单日期</span></span><br><span class="line">        self.order_id = order_id    <span class="comment"># 订单ID</span></span><br><span class="line">        self.money = money          <span class="comment"># 订单金额</span></span><br><span class="line">        self.province = province    <span class="comment"># 销售省份</span></span><br><span class="line"></span><br><span class="line">    <span class="comment"># 通过魔术方法 ，转变为字符串或者说直接被print输出的行为</span></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__str__</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="keyword">return</span> <span class="string">f&quot;<span class="subst">&#123;self.date&#125;</span>,<span class="subst">&#123;self.order_id&#125;</span>,<span class="subst">&#123;self.money&#125;</span>,<span class="subst">&#123;self.province&#125;</span>&quot;</span></span><br></pre></td></tr></table></figure>

<h3 id="4-代码文件-file-define-py"><a href="#4-代码文件-file-define-py" class="headerlink" title="4.代码文件 file_define.py"></a>4.代码文件 file_define.py</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">和文件相关的类定义</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="keyword">import</span> json</span><br><span class="line"></span><br><span class="line"><span class="comment"># 先定义一个抽象类用来做顶层设计，确定有哪些功能需要实现</span></span><br><span class="line"><span class="keyword">from</span> data_define <span class="keyword">import</span> Record</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">FileReader</span>:</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">read_data</span>(<span class="params">self</span>) -&gt; <span class="built_in">list</span>[Record]:</span><br><span class="line">        <span class="string">&quot;&quot;&quot;读取文件的数据，读到的每一条数据都转换为Record对象，将它们都封装到list内返回即可&quot;&quot;&quot;</span></span><br><span class="line">        <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">TextFileReader</span>(<span class="title class_ inherited__">FileReader</span>):</span><br><span class="line">    <span class="comment"># 构造函数</span></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__init__</span>(<span class="params">self, path</span>):</span><br><span class="line">        self.path = path  <span class="comment"># 定义成员变量记录文件的路径</span></span><br><span class="line"></span><br><span class="line">    <span class="comment"># 复写(实现抽象方法) 父类的方法</span></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">read_data</span>(<span class="params">self</span>) -&gt; <span class="built_in">list</span>[Record]:</span><br><span class="line">        <span class="comment"># 打开数据文件</span></span><br><span class="line">        f = <span class="built_in">open</span>(self.path, <span class="string">&#x27;r&#x27;</span>, encoding=<span class="string">&#x27;UTF-8&#x27;</span>)</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 定义一个空列表，用于返回数据</span></span><br><span class="line">        record_list = []  <span class="comment"># type:<span class="built_in">list</span>[Record]</span></span><br><span class="line"></span><br><span class="line">        <span class="comment"># 读取文件</span></span><br><span class="line">        <span class="keyword">for</span> line <span class="keyword">in</span> f.readlines():</span><br><span class="line">            line = line.strip()  <span class="comment"># 去除首尾空格，或者去除读取每一行数据中的\n</span></span><br><span class="line">            data_list = line.split(<span class="string">&quot;,&quot;</span>)  <span class="comment"># 通过，分割，返回列表数据</span></span><br><span class="line">            record = Record(data_list[<span class="number">0</span>], data_list[<span class="number">1</span>], <span class="built_in">int</span>(data_list[<span class="number">2</span>]), data_list[<span class="number">3</span>])</span><br><span class="line">            record_list.append(record)</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 关闭文件</span></span><br><span class="line">        f.close()</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 返回数据</span></span><br><span class="line">        <span class="keyword">return</span> record_list</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">JsonFileReader</span>(<span class="title class_ inherited__">FileReader</span>):</span><br><span class="line">    <span class="comment"># 构造函数</span></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__init__</span>(<span class="params">self, path</span>):</span><br><span class="line">        self.path = path  <span class="comment"># 定义成员变量记录文件的路径</span></span><br><span class="line"></span><br><span class="line">    <span class="comment"># 复写</span></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">read_data</span>(<span class="params">self</span>) -&gt; <span class="built_in">list</span>[Record]:</span><br><span class="line">        <span class="comment"># 打开数据文件</span></span><br><span class="line">        f = <span class="built_in">open</span>(self.path, <span class="string">&#x27;r&#x27;</span>, encoding=<span class="string">&#x27;UTF-8&#x27;</span>)</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 定义一个空列表，用于返回数据</span></span><br><span class="line">        record_list = []  <span class="comment"># type:<span class="built_in">list</span>[Record]</span></span><br><span class="line"></span><br><span class="line">        <span class="comment"># 读取文件</span></span><br><span class="line">        <span class="keyword">for</span> line <span class="keyword">in</span> f.readlines():</span><br><span class="line">            data_dict = json.loads(line)</span><br><span class="line">            record = Record(data_dict[<span class="string">&#x27;date&#x27;</span>], data_dict[<span class="string">&#x27;order_id&#x27;</span>], <span class="built_in">int</span>(data_dict[<span class="string">&#x27;money&#x27;</span>]), data_dict[<span class="string">&#x27;province&#x27;</span>])</span><br><span class="line">            record_list.append(record)</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 关闭文件</span></span><br><span class="line">        f.close()</span><br><span class="line">        <span class="comment"># 返回数据</span></span><br><span class="line">        <span class="keyword">return</span> record_list</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 测试</span></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">    text_file_reader = TextFileReader(<span class="string">&quot;/Volumes/E盘/资料/数据分析案例/2011年1月销售数据.txt&quot;</span>)</span><br><span class="line">    Json_file_reader = JsonFileReader(<span class="string">&quot;/Volumes/E盘/资料/数据分析案例/2011年2月销售数据JSON.txt&quot;</span>)</span><br><span class="line">    list_1 = text_file_reader.read_data()</span><br><span class="line">    list_2 = Json_file_reader.read_data()</span><br><span class="line"></span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> list_1:</span><br><span class="line">        <span class="built_in">print</span>(i)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">for</span> l <span class="keyword">in</span>  list_2:</span><br><span class="line">        <span class="built_in">print</span>(l)</span><br></pre></td></tr></table></figure>

<h3 id="5-代码主文件-main-py"><a href="#5-代码主文件-main-py" class="headerlink" title="5.代码主文件 main.py"></a>5.代码主文件 main.py</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">面向对象，数据分析案例，主业务逻辑代码</span></span><br><span class="line"><span class="string">实现步骤</span></span><br><span class="line"><span class="string">1、设计一个类，可以完成数据的封装</span></span><br><span class="line"><span class="string">2、设计一个抽象类，定义文件读取的相关功能，并使用子类实现具体功能</span></span><br><span class="line"><span class="string">3、读取文件，生产数据对象</span></span><br><span class="line"><span class="string">4、进行数据需求的逻辑计算（计算每一天的销售额）</span></span><br><span class="line"><span class="string">5、通过PyEcharts进行图形绘制</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 先导包</span></span><br><span class="line"><span class="keyword">from</span> file_define <span class="keyword">import</span> FileReader, TextFileReader, JsonFileReader</span><br><span class="line"><span class="keyword">from</span> data_define <span class="keyword">import</span> Record</span><br><span class="line"><span class="keyword">from</span> pyecharts.charts <span class="keyword">import</span> Bar  <span class="comment"># 导入柱状图包</span></span><br><span class="line"><span class="keyword">from</span> pyecharts.options <span class="keyword">import</span> *  <span class="comment"># 构建配置项</span></span><br><span class="line"><span class="keyword">from</span> pyecharts.<span class="built_in">globals</span> <span class="keyword">import</span> ThemeType  <span class="comment"># 主题配置</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 1、打开数据文件</span></span><br><span class="line">text_file_reader = TextFileReader(<span class="string">&quot;/Volumes/E盘/资料/数据分析案例/2011年1月销售数据.txt&quot;</span>)</span><br><span class="line">json_file_reader = JsonFileReader(<span class="string">&quot;/Volumes/E盘/资料/数据分析案例/2011年2月销售数据JSON.txt&quot;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 2、分别读取一月和二月的文件内容</span></span><br><span class="line">jan_data = text_file_reader.read_data()  <span class="comment"># type: <span class="built_in">list</span>[Record]</span></span><br><span class="line">fen_data = json_file_reader.read_data()  <span class="comment"># type: <span class="built_in">list</span>[Record]</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 3、将2个月份的数据合并为1个list来存储</span></span><br><span class="line">all_data: <span class="built_in">list</span>[Record] = jan_data + fen_data</span><br><span class="line"></span><br><span class="line"><span class="comment"># 4、开始进行数据计算（计算每一天的销售额）</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 思路： 字典格式  &#123;&quot;日期 2011-01-01&quot;：总金额 1234，&quot;2011-01-02&quot;：300 ,&quot;2011-01-03&quot;:500&#125;</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 定义一个空字典用来存储</span></span><br><span class="line">data_dict = &#123;&#125;</span><br><span class="line"><span class="keyword">for</span> record <span class="keyword">in</span> all_data:</span><br><span class="line">    <span class="keyword">if</span> record.date <span class="keyword">in</span> data_dict.keys():</span><br><span class="line">        <span class="comment"># 当前日期已经有记录，所以和老记录做累加即可</span></span><br><span class="line">        data_dict[record.date] += record.money</span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        <span class="comment"># 如果当前记录不存在，说明日期是第一次记录，则记录赋值</span></span><br><span class="line">        data_dict[record.date] = record.money</span><br><span class="line"></span><br><span class="line"><span class="comment"># 5、绘图</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 5_1 构建一个柱状图类对象</span></span><br><span class="line">bar = Bar(init_opts=InitOpts(</span><br><span class="line">    <span class="comment"># 设置主题</span></span><br><span class="line">    theme=ThemeType.LIGHT</span><br><span class="line">))</span><br><span class="line"></span><br><span class="line"><span class="comment"># 5_2 添加X轴和Y轴数据</span></span><br><span class="line">bar.add_xaxis(<span class="built_in">list</span>(data_dict.keys()))</span><br><span class="line">bar.add_yaxis(<span class="string">&quot;销售额&quot;</span>,<span class="built_in">list</span>(data_dict.values()),label_opts=LabelOpts(</span><br><span class="line">    is_show=<span class="literal">False</span> <span class="comment"># 不显示数据</span></span><br><span class="line">))</span><br><span class="line"><span class="comment"># 5_3  配置标题</span></span><br><span class="line">bar.set_global_opts(</span><br><span class="line">    title_opts=TitleOpts(title=<span class="string">&quot;每日销售额&quot;</span>)</span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 5_4 开始生成绘图</span></span><br><span class="line">bar.render(<span class="string">&quot;每日销售额柱状图.html&quot;</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="http://grace.666443.xyz">王扣</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://grace.666443.xyz/posts/6ebaa02b.html">http://grace.666443.xyz/posts/6ebaa02b.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://grace.666443.xyz" target="_blank">王扣笔记</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="https://p.ananas.chaoxing.com/star3/origin/d24d9bfcd4ce3f910d6b5cdc78676d75.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/posts/2b5a0751.html"><img class="prev-cover" src="https://p.ananas.chaoxing.com/star3/origin/2a1821704670b5cf8c2289255e183d62.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">15.Python之Mysql数据库相关</div></div></a></div><div class="next-post pull-right"><a href="/posts/18141c11.html"><img class="next-cover" src="https://p.ananas.chaoxing.com/star3/origin/4f58efcc75f80e499f83b69e6a40f221.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">13.Python综合案例-动态柱状图</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">王扣</div><div class="author-info__description">常用开发中的笔记记录</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">22</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">1</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">4</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">This is my Blog 技术笔记</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#Python%E7%AC%AC%E4%BA%8C%E9%98%B6%E6%AE%B5-%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1"><span class="toc-number">1.</span> <span class="toc-text">Python第二阶段 - 面向对象</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AB%A0%E8%8A%82%E7%9B%AE%E5%BD%95"><span class="toc-number">1.1.</span> <span class="toc-text">章节目录</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%9D%E8%AF%86%E5%AF%B9%E8%B1%A1"><span class="toc-number">1.2.</span> <span class="toc-text">初识对象</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%88%90%E5%91%98%E6%96%B9%E6%B3%95"><span class="toc-number">1.3.</span> <span class="toc-text">成员方法</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%B1%BB%E5%92%8C%E5%AF%B9%E8%B1%A1"><span class="toc-number">1.4.</span> <span class="toc-text">类和对象</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95"><span class="toc-number">1.5.</span> <span class="toc-text">构造方法</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%85%B6%E4%BB%96%E5%86%85%E7%BD%AE%E6%96%B9%E6%B3%95"><span class="toc-number">1.6.</span> <span class="toc-text">其他内置方法</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B0%81%E8%A3%85"><span class="toc-number">1.7.</span> <span class="toc-text">封装</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B0%81%E8%A3%85-%E7%BB%83%E4%B9%A0%E9%A2%98%E8%AE%B2%E8%A7%A3"><span class="toc-number">1.8.</span> <span class="toc-text">封装 - 练习题讲解</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%BB%A7%E6%89%BF"><span class="toc-number">1.9.</span> <span class="toc-text">继承</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E7%BB%A7%E6%89%BF%E7%9A%84%E5%9F%BA%E7%A1%80%E8%AF%AD%E6%B3%95"><span class="toc-number">1.9.1.</span> <span class="toc-text">1.继承的基础语法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E5%A4%8D%E5%86%99%E5%92%8C%E4%BD%BF%E7%94%A8%E7%88%B6%E7%B1%BB%E6%88%90%E5%91%98"><span class="toc-number">1.9.2.</span> <span class="toc-text">2.复写和使用父类成员</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%B1%BB%E5%9E%8B%E6%B3%A8%E8%A7%A3"><span class="toc-number">1.10.</span> <span class="toc-text">类型注解</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E5%8F%98%E9%87%8F%E7%9A%84%E7%B1%BB%E5%9E%8B%E6%B3%A8%E8%A7%A3"><span class="toc-number">1.10.1.</span> <span class="toc-text">1.变量的类型注解</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E5%87%BD%E6%95%B0-%E6%96%B9%E6%B3%95-%E7%9A%84%E7%B1%BB%E5%9E%8B%E6%B3%A8%E8%A7%A3"><span class="toc-number">1.10.2.</span> <span class="toc-text">2.函数(方法)的类型注解</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-Union%E7%B1%BB%E5%9E%8B"><span class="toc-number">1.10.3.</span> <span class="toc-text">3.Union类型</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%A4%9A%E6%80%81"><span class="toc-number">1.11.</span> <span class="toc-text">多态</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90%E7%9A%84%E7%BB%BC%E5%90%88%E6%A1%88%E4%BE%8B"><span class="toc-number">1.12.</span> <span class="toc-text">数据分析的综合案例</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#0-%E6%95%B0%E6%8D%AE%E6%9D%A5%E6%BA%90"><span class="toc-number">1.12.1.</span> <span class="toc-text">0.数据来源</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E6%80%9D%E8%B7%AF%E5%88%86%E6%9E%90"><span class="toc-number">1.12.2.</span> <span class="toc-text">1.思路分析</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E4%BB%A3%E7%A0%81%E7%9B%AE%E5%BD%95-%E5%88%86%E4%B8%BA%E5%87%A0%E4%B8%AA%E6%96%87%E4%BB%B6%E5%86%99%E7%9A%84"><span class="toc-number">1.12.3.</span> <span class="toc-text">2.代码目录 分为几个文件写的</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-%E4%BB%A3%E7%A0%81%E6%96%87%E4%BB%B6-data-define-py"><span class="toc-number">1.12.4.</span> <span class="toc-text">3.代码文件 data_define.py</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-%E4%BB%A3%E7%A0%81%E6%96%87%E4%BB%B6-file-define-py"><span class="toc-number">1.12.5.</span> <span class="toc-text">4.代码文件 file_define.py</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-%E4%BB%A3%E7%A0%81%E4%B8%BB%E6%96%87%E4%BB%B6-main-py"><span class="toc-number">1.12.6.</span> <span class="toc-text">5.代码主文件 main.py</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/posts/ae1a0acd.html" title="18.Python爬虫-requests模块"><img src="https://p.ananas.chaoxing.com/star3/origin/b230c5f9060b1f422a86e332d8e37926.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="18.Python爬虫-requests模块"/></a><div class="content"><a class="title" href="/posts/ae1a0acd.html" title="18.Python爬虫-requests模块">18.Python爬虫-requests模块</a><time datetime="2022-12-08T12:53:30.000Z" title="发表于 2022-12-08 20:53:30">2022-12-08</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/ed7a56b2.html" title="17.Python爬虫-数据解析与提取"><img src="https://p.ananas.chaoxing.com/star3/origin/8f2179d04bfe0e48cc706ae112c97952.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="17.Python爬虫-数据解析与提取"/></a><div class="content"><a class="title" href="/posts/ed7a56b2.html" title="17.Python爬虫-数据解析与提取">17.Python爬虫-数据解析与提取</a><time datetime="2022-12-08T12:52:55.000Z" title="发表于 2022-12-08 20:52:55">2022-12-08</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/5038ed.html" title="16.Python爬虫-基础"><img src="https://p.ananas.chaoxing.com/star3/origin/2054c03c91d338203c730610ead1b303.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="16.Python爬虫-基础"/></a><div class="content"><a class="title" href="/posts/5038ed.html" title="16.Python爬虫-基础">16.Python爬虫-基础</a><time datetime="2022-12-08T12:52:11.000Z" title="发表于 2022-12-08 20:52:11">2022-12-08</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/2b5a0751.html" title="15.Python之Mysql数据库相关"><img src="https://p.ananas.chaoxing.com/star3/origin/2a1821704670b5cf8c2289255e183d62.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="15.Python之Mysql数据库相关"/></a><div class="content"><a class="title" href="/posts/2b5a0751.html" title="15.Python之Mysql数据库相关">15.Python之Mysql数据库相关</a><time datetime="2022-12-08T12:17:02.000Z" title="发表于 2022-12-08 20:17:02">2022-12-08</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/6ebaa02b.html" title="14.Python面向对象"><img src="https://p.ananas.chaoxing.com/star3/origin/d24d9bfcd4ce3f910d6b5cdc78676d75.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="14.Python面向对象"/></a><div class="content"><a class="title" href="/posts/6ebaa02b.html" title="14.Python面向对象">14.Python面向对象</a><time datetime="2022-12-08T12:10:47.000Z" title="发表于 2022-12-08 20:10:47">2022-12-08</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2022 By 王扣</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script src="/js/search/local-search.js"></script><div class="js-pjax"><script>(() => {
  const $mermaidWrap = document.querySelectorAll('#article-container .mermaid-wrap')
  if ($mermaidWrap.length) {
    window.runMermaid = () => {
      window.loadMermaid = true
      const theme = document.documentElement.getAttribute('data-theme') === 'dark' ? 'dark' : 'default'

      Array.from($mermaidWrap).forEach((item, index) => {
        const mermaidSrc = item.firstElementChild
        const mermaidThemeConfig = '%%{init:{ \'theme\':\'' + theme + '\'}}%%\n'
        const mermaidID = 'mermaid-' + index
        const mermaidDefinition = mermaidThemeConfig + mermaidSrc.textContent
        mermaid.mermaidAPI.render(mermaidID, mermaidDefinition, (svgCode) => {
          mermaidSrc.insertAdjacentHTML('afterend', svgCode)
        })
      })
    }

    const loadMermaid = () => {
      window.loadMermaid ? runMermaid() : getScript('https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js').then(runMermaid)
    }

    window.pjax ? loadMermaid() : document.addEventListener('DOMContentLoaded', loadMermaid)
  }
})()</script></div><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="false" data-click="false"></script><div class="fb-customerchat" id="fb-customer-chat" attribution="biz_inbox"></div><script>document.getElementById('fb-root') ? '' : document.body.insertAdjacentHTML('afterend', '<div id="fb-root"></div>')

window.fbAsyncInit = function() {
  FB.init({
    xfbml: true,
    version: 'v15.0'
  });
};

(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = 'https://connect.facebook.net/zh_CN/sdk/xfbml.customerchat.js';
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

if (false) {
  var chatBtnFn = () => {
    var chatBtn = document.getElementById("chat_btn")
    chatBtn.addEventListener("click", function(){
      FB.CustomerChat.show();
    });
  }
  chatBtnFn()
} else {
  if (false) {
    function chatBtnHide () {
      FB.CustomerChat.hide()
    }
    function chatBtnShow () {
      FB.CustomerChat.show(false)
    }
  }
}</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>